
$().ready(function() {
	$.validator.setDefaults({
		submitHandler : function() {
			save();
		}
	});
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		headers:{"JwtAuthorization":JwtAuthorizations,"Authorization":token},
		url: ip + '/sys/category/saveCategory',
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i>";
	$("#signupForm").validate({
		rules : {
			parentId : {
				required : true
			},
			code : {
				required : true
			},
			categoryName : {
				required : true,
			},
			sort : {
				required : true,
                digits : true
				
			}
		},
		messages : {
			parentId : {
				required : icon + "请选择上级分类"
			},
			code : {
				required : icon + "请输入编号"
			},
			categoryName : {
				required : icon + "请输入分类名称",
			},
			sort : {
				required : icon + "请输入排序",
                digits : icon + "请输入数字，正序排序"
			}
		}
	})
}

var selectParent = function(){
	layer.open({
		type:2,
		title:"选择分类",
		area : [ '300px', '450px' ],
		content:"../../../templates/system/classification/classificationTree1.html"
	})
}
function loadDept( parentId,parentName){
	$("#parentId").val(deptId);
	$("#parentName").val(parentName);
}
